package com.yd.sdk.analysis;

import android.os.Handler;
import android.util.Log;

import java.util.HashMap;
import java.util.List;
public class AnalysisManager {

    private List<AnalysisAbstractClass> _analysisList;
    private HashMap<String,AnalysisAbstractClass> _analysisMap = new HashMap<>();
    private Handler _handler;
    public AnalysisManager(List<AnalysisAbstractClass> analysisList)
    {
        _handler = new Handler();
        _analysisList = analysisList;
        for (AnalysisAbstractClass analyis:_analysisList) {
            if(analyis.id !=null && !_analysisMap.containsKey(analyis.id)) {
                _analysisMap.put(analyis.id, analyis);
            }
        }
    }

    public void Initialized(String id,String key)
    {
        _handler.post(new Runnable() {
            @Override
            public void run() {
//                Log.e("AnalysisManager",id +"" + key + "" +_analysisMap.size() +"," + _analysisList.size());
                if(_analysisMap.containsKey(id))
                {
                    _analysisMap.get(id).Initialize(key);
                }
            }
        });
    }


    public void LogEvent(String id,String name,String key,String value)
    {
        _handler.post(new Runnable() {
            @Override
            public void run() {

                Log.e("AnalysisManager",id +"" + name + "" +key +"," + value);
                if(_analysisMap.containsKey(id))
                {
                    _analysisMap.get(id).LogEvent(name,key,value);
                }
            }
        });
    }
}
